package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SerialNumberUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ExpressPackage;
import com.ruoyi.system.mapper.ExpressPackageMapper;
import com.ruoyi.system.service.IExpressPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 快递登记Service业务层处理
 */
@Service
public class ExpressPackageServiceImpl implements IExpressPackageService {

    @Autowired
    private ExpressPackageMapper expressPackageMapper;

    @Override
    public ExpressPackage selectExpressPackageById(Long id) {
        return expressPackageMapper.selectExpressPackageById(id);
    }

    @Override
    public List<ExpressPackage> selectExpressPackageList(ExpressPackage expressPackage) {
        return expressPackageMapper.selectExpressPackageList(expressPackage);
    }

    @Override
    public int insertExpressPackage(ExpressPackage expressPackage) {
        if (StringUtils.isEmpty(expressPackage.getSerial())) {
            expressPackage.setSerial(SerialNumberUtils.generateExpressSerial());
        }
        if (StringUtils.isEmpty(expressPackage.getStatus())) {
            expressPackage.setStatus("pending");
        }
        expressPackage.setCreateTime(DateUtils.getNowDate());
        return expressPackageMapper.insertExpressPackage(expressPackage);
    }

    @Override
    public int updateExpressPackage(ExpressPackage expressPackage) {
        expressPackage.setUpdateTime(DateUtils.getNowDate());
        return expressPackageMapper.updateExpressPackage(expressPackage);
    }

    @Override
    public int deleteExpressPackageByIds(Long[] ids) {
        return expressPackageMapper.deleteExpressPackageByIds(ids);
    }

    @Override
    public int deleteExpressPackageById(Long id) {
        return expressPackageMapper.deleteExpressPackageById(id);
    }
}

